<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html>
 <head>
    <title>仓库信息管理</title>
    <!-- import css and js -->
	<%@ include file="/common/meta.jsp" %>
	<script src="${ctx}/js/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript">
// 		var basic_Url="${ctx}/yd/basic/bomRal";
		var basic_Url="${ctx}/yd/logic/poquote";
		var basic_WUrl="yd/logic/poquote";
		var basic_Title="添加";
		var show_Width=320;
		var show_Hight=150;
		var actionNodeID=null;
		var gysID = null;
		function createSearch(){
			init(2,8,'100,100,100,100','20%');

			//第一行的数据
			addCommon(0,0,"lable","报价单编码：");
			addCommon(0,1,"txtlike","code");
			addCommon(0,2,"lable","供应商名称：");
			addCommon(0,3,"txtlike","gys_name");
			addCommon(0,4,"lable","单据状态：");
			addCommon(0,5,"selectEnum","billstatus","<option></option><option value='0'>草稿</option>"+
					"<option value='1'>待二级审批</option><option value='2'>待三级审批</option><option value='3'>审核完成</option>");
			addCommon(0,6,"lable","供应商联系人：");
			addCommon(0,7,"txtlike","gys_linkman");
		}
		
		function searchAP(){
			if(actionNodeID != null ){
				multipleSearch("#table1",true,"",basic_Url+"/list.do?gysID="+actionNodeID);
				//gysID = null;
			}else{
				multipleSearch("#table1",true,"",basic_Url+"/list.do");
			}
			
		}
		
		
		function gettreeData() 
		 {    
			var manager = null;
			manager = $("#tree1").ligerGetTreeManager(); 
			manager.clear();
	        manager.loadData(null, basic_Url+'/tree.do');
	        manager.collapseAll();
		 }
		
		jQuery(document).ready(function() {
			//创建JQGRID表格
			var grid = $("#table1").ligerGrid({
		        columns: [
		                  
						  { display: 'id', name: 'id', width: 1,hide:1 },
		                  { display: '报价单编码', name: 'code', width: 150 },
		                  { display: '供应商名称', name: 'gysName', width: 100 },
		                  { display: '联系人', name: 'gysLinkman', width: 100 },
// 		                  { display: '物料名称', name: 'materialsname', width: 100 },
// 		                  { display: '物料编码', name: 'materialscode', width: 100 },
// 		                  { display: '物料单价', name: 'price', width: 100 },
		                  { display: '单据状态', name: 'billstatus', width: 90 , 
		                	render: function (item){               		 
	                		  var billStatus=item.billstatus;
	                		  if(billStatus=="0"){
	                			  return "草稿";
	                		  }
	                		  if(billStatus=="1"){
	                			  return "待二级审批";
	                		  }
	                		  if(billStatus=="2"){
	                			  return "待三级审批";
	                		  }
	                		  if(billStatus=="3"){
	                			  return "审核完成";
	                		  }
	                	  }},
	                	  {display: '制单人', name: 'foundPerson', width: 100 },
	                	  { display: '询价日期', name: 'quoteDate', width: 100,
		                	  render: function (item){
		                		  if(item.quoteDate == "" || item.quoteDate==null){
		                			  return;
		                		  }
		                		  var quoteDate=new Date(item.quoteDate);
		                		  return formatDate(quoteDate,"yyyy-MM-dd");
		                	  }},
	                	  { display: '创建人', name: 'dcruser', width: 60 },
		                  { display: '创建时间', name: 'dctime', width: 100,
		                	  render: function (item){
		                		  var cdate=new Date(item.dctime);
		                		  return formatDate(cdate,"yyyy-MM-dd");
		                	  }
		                  },
		                 { display: '备注', name: 'remark', width: 140 }
		                      ],  usePager: true,pageSize:15,pageSizeOptions :[15,30,45,60],enabledSort:false,
		                      url : basic_Url+"/list.do",
		                      width: "100%", height:"95%", checkbox: true,      
		                      onDblClickRow : function (data, rowindex, rowobj){
		                    	  edititem(data);
		                       },
		                      toolbar: { items: [
												  { text: '增加报价单', click: addtype, icon: 'add' },
//  		                                          { text: '修改', click: getSelected, icon: 'modify' },
 		                                          { line: true },
 		                                          { text: '删除', click: delitem, img: '../../../js/ligerUI/skins/icons/delete.gif' }
		                                          ]
		                                          }
		                  });
			$("#pageloading").hide();
			
			
			$("#layout1").ligerLayout({ leftWidth: 200,height: '100%',heightDiff:-24,space:4});
			
			$("#tree1").ligerTree({  
				 url: basic_Url+'/tree.do',
				 nodeWidth: 115,
				 checkbox: false,
		         slide: false,
		         onClick:function(node){
		        	 actionNodeID = node.data.id;
		        	 multipleSearch("#table1",true,"",basic_Url+"/list.do?gysID="+node.data.id);
		         }
		     });
			
			 
			//修改物料
			 function getSelected(){
				 var grid = $("#table1").ligerGetGridManager(); 
					var rows = grid.getCheckedRows();
					var data =grid.getSelectedRow();
					if(rows.length==0 || rows.length > 1){
						$.dialog.alert("请选择一行数据!");
						return false;
					}else{
						edititem(data);
					}
			}
			 function edititem(data){
					var url = basic_WUrl+"/operate/edit/"+data.id+".do";
					ShowIframeDialog("operate","修改报价单",url,320,300);
			 } 
			 
			 function delitem(){
				 var grid = $("#table1").ligerGetGridManager(); 
				 var rows =grid.getSelectedRows();
				 var bol = false;
					if (rows==null){
						$.dialog.alert('请选择需要操作删除的行！');
						return;
					}else{
						for(var i=0;i<rows.length;i++){
						 	if (rows[i].dcruser !='${user.name}'){
						 		bol = true;
							}
						}
						if(bol){
							$.dialog.alert('只能对本人建的单据进行删除操作!');
							return;
						}else{
							bol = false;
							for(var i=0;i<rows.length;i++){
							 	if (rows[i].billstatus>0){
							 		bol = true;
								}
							}
							if(bol){
								$.dialog.alert('草稿状态的单据才能进行删除!');
								return;
							}else{
								del();
								bol = false;
							}
						}
					}
			 }
			 
			 //添加组
				 function addtype(){
					 	if(actionNodeID == null || actionNodeID.length<=0){
				 		$.dialog.alert("请选择供应商");
				 		return false;
				 	}
					var url = basic_WUrl+"/operate/add/"+actionNodeID+".do";
					ShowIframeDialog("operate",basic_Title,url,show_Width,show_Hight);
			 }
			 
			 
		});
	</script>
	
  </head>
<!-- <body onLoad="createSearch()">
   <div id="layout1">-->
    	<!-- <div class="panelBar">
	            <ul class="toolBar">
		           <li><a class="add" onclick="add()"><span>添加</span></a></li>
				   <li><a class="delete" onclick="del()"><span>删除</span></a></li>
               </ul>
          </div> 
         
   			
      </div>
</body> -->
 <body style="padding:10px" onLoad="createSearch()">  
       <div id="pageHeader" class="pageHeader">
               <div class="searchBar" id="multipleSearchDialog">
	                <table class="table" width="100%" id="searchHeader" >  
                        <tbody id="newbody">
                        </tbody>
 	                </table>
                    <div class="subBar">
			             <ul>
				             <li><div class="buttonActive"><div class="buttonContent"><button type="submit" id="btnSearch" onclick="searchAP()">查询</button></div></div></li>
				             <li><a class="button" onclick="clearSearch()"><span>重置</span></a></li>
			             </ul>
	                </div>
               </div>
          </div>
      <div id="layout1">
            <div position="left" title="供应商列表">
            <div style="width:200px; height:450px; float:left;overflow:auto;  ">
   				 <ul id="tree1"></ul>
    		</div> 
            </div>
            <div position="center" title="报价单列表" id="table1">
            
            </div>  
        </div> 
    </body>
</html>